﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LevenBlog.Core.Entities;

namespace LevenBlog.Core.Data
{
    public interface IDbHelper
    {
        #region 数据库操作

        int ExecuteNonQuery(IDbProvider provider, string sqlString);

        int ExecuteNonQuery(IDbProvider provider, string sqlString, params IDataParameter[] sqlParas);

        object ExecuteScalar(IDbProvider provider, string sqlString);

        object ExecuteScalar(IDbProvider provider, string sqlString, params IDataParameter[] sqlParas);

        IDataReader ExecuteDataReader(IDbProvider provider, string sqlString);

        IDataReader ExecuteDataReader(IDbProvider provider, string sqlString, params IDataParameter[] sqlParas);

        DataTable ExecuteDataTable(IDbProvider provider, string sqlString);

        DataTable ExecuteDataTable(IDbProvider provider, string sqlString, params IDataParameter[] sqlParas);

        #endregion

        #region 创建DataParameter

        IDataParameter CreateParameter(string name);

        IDataParameter CreateParameter(string name, object value);

        IDataParameter CreateParameter(string name, DataType type);

        IDataParameter CreateParameter(string name, DataType type, int size);

        IDataParameter CreateParameter(string name, DataType type, int size, object value);

        IDataParameter CreateParameter(string name, DataType type, object value);

        #endregion

        #region EntityHelper

        string CreateInsertSql(IEntity entity, out IDataParameter[] paras);

        string CreateUpdateSql(IEntity entity, out IDataParameter[] paras);

        EType ConvertToEntity<EType>(IDataReader reader) where EType : IEntity, new();

        IList<EType> ConvertToList<EType>(IDataReader reader) where EType : IEntity, new();

        EType ConvertToEntity<EType>(IDataReader reader, string prefix) where EType : IEntity, new();

        IList<EType> ConvertToList<EType>(IDataReader reader, string prefix) where EType : IEntity, new();

        EType ConvertSomeToEntity<EType>(IDataReader reader) where EType : IEntity, new();

        IList<EType> ConvertSomeToList<EType>(IDataReader reader) where EType : IEntity, new();

        EType ConvertSomeToEntity<EType>(IDataReader reader, string prefix) where EType : IEntity, new();

        IList<EType> ConvertSomeToList<EType>(IDataReader reader, string prefix) where EType : IEntity, new();

        #endregion

        #region 反射属性部分

        object GetPropertyValue(IEntity entity, string name);

        VType GetPropertyValue<VType>(IEntity entity, string name);

        void SetPropertyValue(IEntity entity, string name, object value);

        #endregion
    }
}
